package cn.edu.scau.cmi.liangzijian.adapter;

import java.util.ArrayList;
import java.util.List;

public class StudentTable {
	private List<Student> students = null;
	
	private StudentTable() {
		students = new ArrayList<Student>();
	}
	
	boolean add(Student student) {
		return students.add(student);
	}
	
	Student remove(int id) {
		for(Student student : students) {
			if(student.getId() == id) {
				students.remove(student);
				return student;
			}
		}
		return null;
	}
	
	boolean remove(Student student) {
		return students.remove(student);
	}
	
	Student get(int id) {
		for(Student student : students) {
			if(student.getId() == id) {
				return student;
			}
		}
		return null;
	}
	
	boolean contains(int id) {
		for(Student student : students) {
			if(student.getId() == id) {
				return true;
			}
		}
		return false;
	}
	
	List<Student> getStudents() {
		return students;
	}
	
	
	String[] getStudentsInfo() {
		String[] info = new String[students.size()];
		
		int i = 0;
		for(Student student : students) {
			info[i++] = student.toString();
		}
		return info;
	}
	
	void showStudentsInfo() {
		for(Student student : students) {
			System.out.println(student);
		}
	}
	
	static StudentTable getInstance() {
		return new StudentTable();
	}
}
